$package('itsm.user');

itsm.user.registerUserMain=function(){
	this.opt='';
	return {
		//列表
		registerUserMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'registerUser!findRegisterUserPager.action',
				caption:'玩家列表',
				colNames:['ID','会员','姓名','登录密码','查询密码','冻结','级别','推荐人','注册时间','激活时间','用户状态','运营中心','子账户','手机','QQ','email','运营中心申请状态','运营中心'],
			 	colModel:[
			 	          {name:'registerUserId',align:'center',width:'40px'},
			 	          {name:'loginName',align:'left',width:'80px'},
			 	          {name:'asUserName',align:'left',width:'80px'},
			 	          {name:'password1',align:'left',width:'65px'},
			 	          {name:'password2',align:'left',width:'65px'},
			 	          {name:'userStatus',align:'center',width:'40px',formatter:function(v,v1,v2){
			 	        	 if(v=='1'){
			 	        		  return "<span style='color:red;'>冻结</span>";
			 	        	  }else{
			 	        		 return "<span style='color:green;'>正常</span>";
			 	        	  }
			 	          }},
			 	          {name:'registerLevel',align:'left',width:'50px',formatter:function(v,v1,v2){
			 	        	  if(v=='L1'){
			 	        		 return "一星";
			 	        	  }else if(v=='L2'){
			 	        		  return "二星";
			 	        	  }else if(v=='L3'){
			 	        		  return "三星";
			 	        	  }else if(v=='L4'){
			 	        		  return "四星";
			 	        	  }else if(v=='L5'){
			 	        		  return "五星";
			 	        	  }else if(v=='L6'){
			 	        		  return "伯爵卡";
			 	        	  }else if(v=='L7'){
			 	        		  return "子帐户";
			 	        	  }
			 	        	  
			 	          }},
			 	          {name:'recommendUser',align:'left',width:'80px'},
			 	          {name:'registerTime',align:'left',width:'140px'},
			 	          {name:'activationTime',align:'left',width:'140px'},
			 	          {name:'status',align:'left',width:'80px',formatter:function(v,v1,v2){
			 	        	  if(v=="Activation"){
			 	        		  return "已完善";
			 	        	  }else if(v=="unfinished"){
			 	        		  return "<span style='color:red;'>待完善信息</span>";
			 	        	  }else{
			 	        		  return "<span style='color:red;'>未激活</span>";
			 	        	  }
			 	          }},
			 	          {name:'declarationCenters',align:'left',width:'80px',hidden:false},
			 	          {name:'parentAccount',align:'center',width:'40px',hidden:true,formatter:function(v,v1,v2){
			 	        	 //console.log(v);
			 	        	  if(v && v != null && v.length > 0){
			 	        		  return "<span style='color:red;'>是</span>";//"是（"+v+"）";
			 	        	  }else{
			 	        		  return "否";
			 	        	  }
			 	          }},
			 	          {name:'mobile',align:'left',width:'100px'},
			 	          {name:'qq',align:'left',hidden:true,width:'40px'},
			 	          {name:'email',align:'left',width:'120px'},
			 	          {name:'applyDeclarationCenter',align:'left',width:'60px',hidden:true},
			 	          {name:'declarationCenter',index:'isDeclarationCenter',align:'center',width:'60px',hidden:false,formatter:function(v,v1,v2){
			 	        	  if(v){
			 	        		  return "<span style='color:red;'>是</span>";
			 	        	  }else{
			 	        		 return "否";
			 	        	  }
			 	          }}
			 	          
			 	         
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "registerUserId"}),
				sortname:'registerUserId',
				shrinkToFit:false,
				ondblClickRow:function(rowId){
					//itsm.user.registerUserMain.showAccountInfo(rowId)
				},
				pager:'#registerUserMainPager'
				});
				$("#registerUserMainGrid").jqGrid(params);
				$("#registerUserMainGrid").navGrid('#registerUserMainPager',navGridParams);
				//列表操作项
				$("#t_registerUserMainGrid").css(jqGridTopStyles);
				$("#t_registerUserMainGrid").html($('#registerUserMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#registerUserMainGrid","regCenter",10);
		},
		//查看账号信息
		showAccountInfo:function(rowId){
			var rowData = $('#registerUserMainGrid').getRowData(rowId);
			$.post('account!findAccountInfoByLoginName.action','loginName='+rowData.loginName,function(data){
				if(data!=null){
					$('#regUserMain_status').text(data.status);
					$('#regUserMain_balance').text(data.balance);
					$('#regUserMain_haveShare').text(data.haveShare);
					$('#regUserMain_manualBuyQuota').text(data.manualBuyQuota);
					$('#regUserMain_manualBuyQuotaTotal').text(data.manualBuyQuotaTotal);
					$('#regUserMain_autoBuyQuota').text(data.autoBuyQuota);
					$('#regUserMain_autoBuyQuotaTotal').text(data.autoBuyQuotaTotal);
					$('#regUserMain_percentageSeventy').text(data.percentageSeventy);
					$('#regUserMain_percentageThirty').text(data.percentageThirty);
					
					$('#regUserMain_accountWallet').text(data.accountWallet);
					$('#regUserMain_autoUpgradeWallet').text(data.autoUpgradeWallet);
					$('#regUserMain_purchaseShareWallet').text(data.purchaseShareWallet);
				}
			});
		},
		//打开添加窗口
		openAddWin:function(){
			opt='saveRegiserUser';
			resetForm('#registerUserMain_add_form');
			$('#registerUserMain_add_win').window('open');
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='editRegisterUser';
			checkBeforeEditGrid('#registerUserMainGrid',function(rowData){
				$.post('registerUser!findRegisterUserByIdOrLoginName.action','registerUserQueryDTO.loginName='+rowData.loginName,function(data){
					$('#registerUserMain_registerUserId').val(data.registerUserId);
					$('#registerUserMain_loginName').val(data.loginName);
					$('#registerUserMain_userName').val(data.userName);
					$('#registerUserMain_accountType').val(data.accountType);
					$('#registerUserMain_bankAccount').val(data.bankAccount);
					$('#registerUserMain_email').val(data.email);
					$('#registerUserMain_mobile').val(data.mobile);
					$('#registerUserMain_qq').val(data.qq);
					$('#registerUserMain_recommendUser').val(data.recommendUser);
				});
				$('#registerUserMain_add_win').window('open');
			});	
		},
		
		//保存
		saveRegisterUser:function(){
			if($('#registerUserMain_add_win').form('validate')){
				var _param = $('#registerUserMain_add_form').serialize();
				$.post('registerUser!'+opt+'.action',_param,function(data){
					msgShow('保存成功!','show');
					$('#registerUserMain_add_win').window('close');
					$('#registerUserMainGrid').trigger('reloadGrid');
				})
			}
		},
		//删除
		deleteRegisterUser:function(){
			checkBeforeDeleteGrid('#registerUserMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("registerUser!deleteRegisterUser.action", pp, function(data){
					$('#registerUserMainGrid').trigger('reloadGrid');
					msgShow(data,'show');
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#registerUserMain_search_win').window('open');
		},
		//搜索
		searchRegisterUser:function(){
			var sdata=$('#registerUserMain_search_form').getForm();
			var postData = $("#registerUserMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'registerUser!findRegisterUserPager.action';		
			$('#registerUserMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		//打开修改账号信息窗口
		openUpdateAccount:function(){
			checkBeforeEditGrid('#registerUserMainGrid',function(rowData){
				$.post('account!findAccountInfoByLoginName.action','loginName='+rowData.loginName,function(data){
					if(data!=null){
						$('#registerUserMain_accountId').val(data.accountId);
						$('#registerUserMain_balance').val(data.balance);
						$('#registerUserMain_haveShare').val(data.haveShare);
						$('#registerUserMain_manualBuyQuota').val(data.manualBuyQuota);
						$('#registerUserMain_manualBuyQuotaTotal').val(data.manualBuyQuotaTotal);
						$('#registerUserMain_autoBuyQuota').val(data.autoBuyQuota);
						$('#registerUserMain_autoBuyQuotaTotal').val(data.autoBuyQuotaTotal);
						$('#registerUserMain_percentageSeventy').val(data.percentageSeventy);
						$('#registerUserMain_percentageThirty').val(data.percentageThirty);
					}
					
					$('#registerUserMain_updateAccount_win').window('open');
				});
			});	
			
		},
		//修改账号信息
		updateAccount:function(){
			var _param = $('#registerUserMain_updateAccount_form').serialize();
			$.post('account!updateAccount.action',_param,function(data){
				msgShow('保存成功!','show');
				$('#registerUserMain_updateAccount_win').window('close');
			})
		},
		//修改账号密码
		changePassword:function(){
			checkBeforeEditGrid('#registerUserMainGrid',function(rowData){
				$.post('registerUser!findRegisterUserByIdOrLoginName.action','registerUserQueryDTO.loginName='+rowData.loginName,function(data){
					$('#registerUserMain_changePassword_loginName').val(data.loginName);
					$('#registerUserMain_password1').val(data.password1);
					$('#registerUserMain_password2').val(data.password2);
					$('#registerUserMain_passwordProblem').val(data.passwordProblem);
					$('#registerUserMain_passwordAnswer').val(data.passwordAnswer);
				});
				$('#registerUserMain_changePassword_win').window('open');
			});	
		},
		changePasswordSave:function(){
			var _param = $('#registerUserMain_changePassword_form').serialize();
			$.post('registerUser!changePasswordByAdmin.action',_param,function(data){
				msgShow(data,'show');
				$('#registerUserMain_changePassword_win').window('close');
			})
		},
		openOrCloseDeclarationCenter:function(){
			checkBeforeEditGrid('#registerUserMainGrid',function(rowData){
				
				$.post('registerUser!openOrCloseDeclarationCenter.action','registerUserDTO.loginName='+rowData.loginName,function(data){
					msgShow('操作成功!','show');
					$('#registerUserMainGrid').trigger('reloadGrid');
				})
				
			});
			
		},
		openRechargeWin:function(){
			$('#registerUserMain_recharge_win').window('open');
		},
		openRechargeOpt:function(){
			var _param = $('#registerUserMain_recharge_form').serialize();
			$.post('account!recharge.action',_param,function(data){
				msgShow('充值成功!','show');
				$('#registerUserMain_recharge_win').window('close');
			})
		},
		
		changeUserStatus:function(userStatus){
			
			var rowIds = $('#registerUserMainGrid').getGridParam('selarrrow');
			
			if(rowIds==''){
				msgAlert(i18n['msg_atLeastChooseOneData'],'info');
			}
			else
			{
				$.messager.confirm(i18n['msg_msg'],'<br/>确认要冻结或解冻账号吗？',function(r){
					if(r){
						var pp = $.param({'ids':rowIds},true);
						$.post("registerUser!changeUserStatus.action", pp+'&userStatus='+userStatus, function(data){
							$('#registerUserMainGrid').trigger('reloadGrid');
							msgShow('修改成功!','show');
						}, "json");
					}
				});
			}
		},
		
		init:function(){
			itsm.user.registerUserMain.registerUserMainGrid();
		}
	}
	
}();

$(function(){
	itsm.user.registerUserMain.init();
});